package com.wash.shoes.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.wash.shoes.domain.dto.OrderTransportPageDto;
import com.wash.shoes.domain.dto.ShopStsXcxDto;
import com.wash.shoes.entity.OrderTransportPo;
import com.wash.shoes.mapper.OrderTransportMapper;
import com.wash.shoes.mapper.UserShopMapper;
import com.wash.shoes.page.PageFactory;
import com.wash.shoes.service.OrderTransportService;
import com.wash.shoes.util.AdminUserUtil;
import com.wash.shoes.util.HeaderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 订单的商品 服务实现类
 * </p>
 *
 * @author ljg
 * @since 2024-09-16
 */
@Service
public class OrderTransportServiceImpl extends ServiceImpl<OrderTransportMapper, OrderTransportPo> implements OrderTransportService {


    @Override
    public List<OrderTransportPo> getByOrderId(String orderId) {
        return this.baseMapper.getByOrderId(orderId);
    }

    @Override
    public OrderTransportPo getOneByOrderId(String orderId) {
        return this.baseMapper.getOneByOrderId(orderId);
    }

    @Autowired
    private UserShopMapper userShopMapper;

    @Override
    public Page<OrderTransportPo> pageList(OrderTransportPageDto transportPo) {
        Page<OrderTransportPo> page = PageFactory.defaultPage();
        // 用户账号绑定的类型
        Long userId = SecurityUtils.getUserId();
        // 获取用户绑定的类型,
        List<String> userBindTypeList = userShopMapper.getUserBindType(userId + "");
        String userBindType = null;
        if (!CollectionUtils.isEmpty(userBindTypeList)) {
            userBindType = userBindTypeList.get(0);
        }
        List<OrderTransportPo> dataList = baseMapper.pageList(page, transportPo, HeaderUtil.getShopIdStr(), userBindType);
        page.setRecords(dataList);
        return page;
    }

    @Override
    public OrderTransportPo getByWayBillCode(String wayBillCode) {
        return this.baseMapper.getByWayBillCode(wayBillCode);
    }

    @Override
    public OrderTransportPo getOneByOrderIdType(String orderId, String type) {
        return this.baseMapper.getOneByOrderIdType(orderId, type);
    }

    @Autowired
    private UserShopMapper userShopMapperStic;

    @Override
    public Integer incomeOrderNum(ShopStsXcxDto shopStsXcxDto) {
        List<String> userBindTypeList = userShopMapperStic.getUserBindType(String.valueOf(AdminUserUtil.getUserId()));
        String userBindType = "";
        if (CollectionUtil.isNotEmpty(userBindTypeList)) {
            userBindType = userBindTypeList.get(0);
        }
        return this.baseMapper.incomeOrderNum(shopStsXcxDto, HeaderUtil.getShopIdStr(), userBindType);
    }

    @Override
    public OrderTransportPo getLastTransport() {
        return this.baseMapper.getLastTransport();
    }

    @Override
    public OrderTransportPo getOneByOrderNoType(String orderNo, String type) {
        return this.baseMapper.getOneByOrderNoType(orderNo, type);
    }


}
